package com.weareint.examples.dto;

import com.weareint.examples.entity.Product;
import com.weareint.common.dto.AbstractDTO;
import com.weareint.common.dto.IBasicDTO;
import com.weareint.common.utils.DateUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 *
 *
 * <pre>
 *      产品DTO
 * </pre>
 *
 * @author Auto Generator
 * @date 2021-07-16
 */
@ApiModel(value = "产品", description = "产品")
@Data
@EqualsAndHashCode(callSuper = true)
public class ProductDTO extends AbstractDTO implements IBasicDTO<Product> {

    @ApiModelProperty(value = "名称")
    private String name;

    @ApiModelProperty(value = "编码")
    private String code;

    @ApiModelProperty(value = "产品类型ID")
    private Long prodTypeId;

    @ApiModelProperty(value = "物料ID")
    private Long materialId;

    @ApiModelProperty(value = "客户ID")
    private Long companyId;

    @ApiModelProperty(value = "网版ID")
    private Long noteId;


    /**
     * <pre>
     *     转化为Entity对象
     * </pre>
     * @return {@link Product}
     */
    @Override
    public Product toEntity() {
        Product entity = new Product();
        entity.setId(this.getId());
        entity.setName(this.getName());
        entity.setCode(this.getCode());
        entity.setProdTypeId(this.getProdTypeId());
        entity.setMaterialId(this.getMaterialId());
        entity.setCompanyId(this.getCompanyId());
        entity.setNoteId(this.getNoteId());
        return entity;
    }

    /**
     * <pre>
     *     依据非空的属性创建一个新Entity
     * </pre>
     * @return {@link Product}
     */
    @Override
    public Product toNewEntityIgnoreNulls() {
        Product unPersistentEntity = new Product();
        toEntityIgnoreNulls(unPersistentEntity);
        return unPersistentEntity;
    }

    /**
     * <pre>
     *     把非空的属性复制到已有的实体上
     * </pre>
     * @param persistentEntity {@link Product}
     */
    @Override
    public void toEntityIgnoreNulls(Product persistentEntity) {
        if (null != this.getCreateTime()){
            persistentEntity.setCreateTime(DateUtil.parse(this.getCreateTime()));
        }
        if (null != this.getUpdateTime()){
            persistentEntity.setUpdateTime(DateUtil.parse(this.getUpdateTime()));
        }
        if (null != this.getCreator()){
            persistentEntity.setCreator(this.getCreator());
        }
        if (null != this.getUpdater()){
            persistentEntity.setUpdater(this.getUpdater());
        }
        if (null != this.getId()){
            persistentEntity.setId(this.getId());
        }
        if (null != this.getName()){
            persistentEntity.setName(this.getName());
        }
        if (null != this.getCode()){
            persistentEntity.setCode(this.getCode());
        }
        if (null != this.getProdTypeId()){
            persistentEntity.setProdTypeId(this.getProdTypeId());
        }
        if (null != this.getMaterialId()){
            persistentEntity.setMaterialId(this.getMaterialId());
        }
        if (null != this.getCompanyId()){
            persistentEntity.setCompanyId(this.getCompanyId());
        }
        if (null != this.getNoteId()){
            persistentEntity.setNoteId(this.getNoteId());
        }
    }


}
